#include <graphics/vertexbuffer.h>
#include <graphics/utils.h>
#include <graphics/vertexarray.h>



namespace yam3d
{
namespace graphics
{

VertexBuffer::VertexBuffer()
: core::Object(__FUNCTION__)
{
}


VertexBuffer::~VertexBuffer()
{
}


void VertexBuffer::addVertexArray( const char* const name, VertexArray* va )
{
    m_vertexArrays[name] = va;
}

void VertexBuffer::setVertexArrays(QGLShaderProgram* program)
{
    for( HashType::iterator it = m_vertexArrays.begin(); it != m_vertexArrays.end(); ++it )
    {
        assert( *it != 0 );
        program->enableAttributeArray(it.key().toStdString().c_str());
        checkGlError("QGLShaderProgram::enableAttributeArray(name=%s)", it.key().toStdString().c_str() );
        it.value()->setAttributeArray(program, it.key().toStdString().c_str());
    }
}

const VertexArray* VertexBuffer::getVertexArray(  const char* const name ) const
{
    return m_vertexArrays[name].ptr();
}


VertexArray* VertexBuffer::getVertexArray(  const char* const name )
{
    return m_vertexArrays[name];
}


}
}

